{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class_01_1_overview.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# T81-558: Applications of Deep Neural Networks\n",
    "**Module 1: Python Preliminaries**\n",
    "* Instructor: [Jeff Heaton](https://sites.wustl.edu/jeffheaton/), McKelvey School of Engineering, [Washington University in St. Louis](https://engineering.wustl.edu/Programs/Pages/default.aspx)\n",
    "* For more information visit the [class website](https://sites.wustl.edu/jeffheaton/t81-558/)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "These installation instructions can be used with the following YouTube videos.\n",
    "\n",
    "* [Installing TensorFlow, Keras, and Python in Windows CPU](https://www.youtube.com/watch?v=RgO8BBNGB8w&list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN)\n",
    "* [Installing TensorFlow, Keras, and Python in Mac](https://www.youtube.com/watch?v=MpUvdLD932c&list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN)\n",
    "* [Installing TensorFlow, Keras, and Python in Windows GPU, warning, somewhat complex](https://www.youtube.com/watch?v=qrkEYf-YDyI&list=PLjy4p-07OYzulelvJ5KVaT2pDlxivl_BN)\n",
    "\n",
    "\n",
    "# Software Installation\n",
    "This class is technically oriented.  A successful student needs to be able to compile and execute Python code that makes use of TensorFlow for deep learning. There are two options for you to accomplish this:\n",
    "\n",
    "* Install Python, TensorFlow and some IDE (Jupyter, TensorFlow, and others)\n",
    "* Use Google CoLab in the cloud\n",
    "\n",
    "Near the top of this document, there are links to videos that describe how to use Google CoLab. There are also videos explaining how to install Python on your local computer.  The following sections take you through the process of installing Python on your local computer.  This process is essentially the same on Windows, Linux, or Mac.  For specific OS instructions, refer to one of the tutorial YouTube videos earlier in this document.\n",
    "\n",
    "Note: This installation uses a YAML installation script that I created for this course.  Older videos used a more hands-on approach that I describe [here](manual_setup.ipynb).  Unless you are using an older version of my class, I suggest using the installation YAML script provided below.\n",
    "\n",
    "## Installing Python and TensorFlow\n",
    "\n",
    "The first step is to install the latest version of MiniConda Python.  As of January 2020, 3.7 is the latest version of Python 3.  I recommend using the MiniConda (Anaconda) release of Python, as it already includes many of the data science related packages that are needed by this class.  Anaconda directly supports Windows, Mac, and Linux.  Miniconda is the minimal set of features from the extensive Anaconda Python distribution.  Download Miniconda from the following URL:\n",
    "\n",
    "* [Miniconda](https://docs.conda.io/en/latest/miniconda.html)\n",
    "\n",
    "## Installing Jupyter\n",
    "\n",
    "We will use Jupyter notebooks extensively in this course. Install Jupyter into your base Python environment.  In the next section, we will create a sub-environment that holds precisely the software we need.  However, it is essential to have a Jupyter notebook installed in your base Python environment. It is easy to install Jupyter notebooks with the following command:\n",
    "\n",
    "```\n",
    "conda install -y jupyter\n",
    "```\n",
    "\n",
    "Next, we will create an environment to hold TensorFlow.\n",
    "\n",
    "# Dealing with TensorFlow incompatibility with Latest Python Versions\n",
    "\n",
    "**VERY IMPORTANT** If a later version of Miniconda than 3.7 is available, then download and install it.  We will create a Python 3.7 environment just for TensorFlow.  Not all TensorFlow 2.0 packages currently support later than Python 3.7.  Usually, you will need to stay one version back from the latest Python to maximize compatibility with standard machine learning packages. \n",
    "\n",
    "You will install all of the needed TensorFlow and machine learning packages with an Anaconda YAML installation script that I provide. The script can be downloaded from here (it is the same script for Windows, Mac, and Linux):\n",
    "\n",
    "* [T81-558: TensorFlow Environment Setup Script: tensorflow.yml](https://raw.githubusercontent.com/jeffheaton/t81_558_deep_learning/master/tensorflow.yml)\n",
    "* [T81-558: TensorFlow Environment Setup Script for GPU: tensorflow-gpu.yml](https://raw.githubusercontent.com/jeffheaton/t81_558_deep_learning/master/tensorflow-gpu.yml)\n",
    "* [Instructions for TensorFlow GPU Setup](https://www.tensorflow.org/install/gpu)\n",
    "\n",
    "Assuming you have MiniConda installed, run the following command from a terminal prompt.  Make sure you downloaded the **tensorflow.yml** script to the same directory so that Conda can find it.\n",
    "\n",
    "```\n",
    "conda env create -v -f tensorflow.yml\n",
    "```\n",
    "\n",
    "To enter this environment, you must use the following command. You must execute this command every time you open a new Anaconda/Miniconda terminal window:\n",
    "\n",
    "```\n",
    "conda activate tensorflow\n",
    "```\n",
    "\n",
    "You must also link your new **tensorflow** environment to Jupyter so that you can choose it as a Kernal.  Always make sure to run your Jupyter notebooks from your 3.7 kernel. You should only need to enter this command once.\n",
    "\n",
    "```\n",
    "python -m ipykernel install --user --name tensorflow --display-name \"Python 3.7 (tensorflow)\"\n",
    "```\n",
    "\n",
    "At this point, you should have a working Python environment for TensorFlow."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python Introduction\n",
    "\n",
    "\n",
    "* [Anaconda v3.6](https://www.continuum.io/downloads) Scientific Python Distribution, including: [Scikit-Learn](http://scikit-learn.org/), [Pandas](http://pandas.pydata.org/), and others: csv, json, numpy, scipy\n",
    "* [Jupyter Notebooks](http://jupyter.readthedocs.io/en/latest/install.html)\n",
    "* [PyCharm IDE](https://www.jetbrains.com/pycharm/)\n",
    "* [Cx_Oracle](http://cx-oracle.sourceforge.net/)\n",
    "* [MatPlotLib](http://matplotlib.org/)\n",
    "\n",
    "## Jupyter Notebooks\n",
    "\n",
    "Space matters in Python, indent code to define blocks\n",
    "\n",
    "Jupyter Notebooks Allow Python and Markdown to coexist.\n",
    "\n",
    "Even LaTeX math:\n",
    "\n",
    "$ f'(x) = \\lim_{h\\to0} \\frac{f(x+h) - f(x)}{h}. $\n",
    "\n",
    "## Python Versions\n",
    "\n",
    "* If you see `xrange` instead of `range`, you are dealing with Python 2\n",
    "* If you see `print x` instead of `print(x)`, you are dealing with Python 2 \n",
    "* This class uses Python 3.6!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tensor Flow Version: 2.0.0\n",
      "Keras Version: 2.2.4-tf\n",
      "\n",
      "Python 3.7.5 (default, Oct 25 2019, 10:52:18) \n",
      "[Clang 4.0.1 (tags/RELEASE_401/final)]\n",
      "Pandas 0.25.3\n",
      "Scikit-Learn 0.21.3\n",
      "GPU is NOT AVAILABLE\n"
     ]
    }
   ],
   "source": [
    "# What version of Python do you have?\n",
    "import sys\n",
    "\n",
    "import tensorflow.keras\n",
    "import pandas as pd\n",
    "import sklearn as sk\n",
    "import tensorflow as tf\n",
    "\n",
    "print(f\"Tensor Flow Version: {tf.__version__}\")\n",
    "print(f\"Keras Version: {tensorflow.keras.__version__}\")\n",
    "print()\n",
    "print(f\"Python {sys.version}\")\n",
    "print(f\"Pandas {pd.__version__}\")\n",
    "print(f\"Scikit-Learn {sk.__version__}\")\n",
    "print(\"GPU is\", \"available\" if tf.test.is_gpu_available() else \"NOT AVAILABLE\")"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3.7 (tensorflow)",
   "language": "python",
   "name": "tensorflow"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
